package com.ai.mapper.provider;

import org.apache.ibatis.jdbc.SQL;

import java.util.Map;

import static org.apache.ibatis.jdbc.SqlBuilder.SELECT;

public class QuestionLibProvider {
    public String questionLibList(Map<String, Object> paramsMap){
        return new SQL(){{
            SELECT("q.id as questionLibId,q.question as question,q.reference_answer as referenceAnswer,q.ai_src as aiSrc,q.is_on as isOn,q.interviewer_id as interviewerId,i.ai_name as interviewerName,q.create_time as createTime,q.updated_time as updatedTime");
            FROM("question_lib q left join interviewer i on q.interviewer_id=i.id");
            String aiName = (String) paramsMap.get("aiName");
            String question = (String) paramsMap.get("question");
            if(aiName != null && !aiName.trim().isEmpty()){
                WHERE("i.ai_name LIKE CONCAT('%', #{aiName}, '%')");
            }
            if(question != null && !question.trim().isEmpty()){
                WHERE("q.question LIKE CONCAT('%', #{question}, '%')");
            }
        }}.toString();
    }
}
